package com.yuanfengerp.inventoryAdjustment.service.impl;


import com.yuanfengerp.inventoryAdjustment.dao.IInventoryAdjustmentDao;
import com.yuanfengerp.inventoryAdjustment.entity.InventoryAdjustment;
import com.yuanfengerp.inventoryAdjustment.service.IInventoryAdjustmentService;
import com.yuanfengerp.publicUtil.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

@Service
public class InventoryAdjustmentServiceImpl implements IInventoryAdjustmentService {
    @Autowired
    private IInventoryAdjustmentDao iiad;
    //根据不同参数查询
    @Override
    public Result<List<InventoryAdjustment>> queryInventoryAdjustment(Map<String, Object> params) {
        List<InventoryAdjustment> inventoryAdjustments = iiad.queryInventoryAdjustment(params);
        if (!inventoryAdjustments.isEmpty()) {
            return Result.success(inventoryAdjustments);
        } else {
            return Result.failure(400, "暂无数据");
        }
    }
    //新增库存调整单
    @Override
    public Result<String> addInventoryAdjustment(InventoryAdjustment inventoryAdjustment) {
        inventoryAdjustment.setOperation_time(new Date());
        inventoryAdjustment.setAudit_time(new Date());
        int i = iiad.addInventoryAdjustment(inventoryAdjustment);
        if (i > 0) {
            return Result.success("添加成功");
        } else {
            return Result.failure(400, "添加失败");
        }
    }
    //根据ID查询库存调整单
    @Override
    public Result<InventoryAdjustment> queryInventoryAdjustmentById(String document_ID) {
        InventoryAdjustment inventoryAdjustment = iiad.queryInventoryAdjustmentById(document_ID);
        if (inventoryAdjustment != null) {
            return Result.success(inventoryAdjustment);
        } else {
            return Result.failure(400, "暂无数据");
        }
    }
    //修改库存调整单
    @Override
    public Result<String> updateInventoryAdjustmentById(InventoryAdjustment inventoryAdjustment) {
        int i = iiad.updateInventoryAdjustmentById(inventoryAdjustment);
        if (i > 0) {
            return Result.success("修改成功");
        } else {
            return Result.failure(400, "修改失败");
        }
    }
    //删除库存调整单
    @Override
    public Result<String> deleteInventoryAdjustment(String document_ID) {
        int i = iiad.deleteInventoryAdjustment(document_ID);
        if (i > 0) {
            return Result.success("删除成功");
        } else {
            return Result.failure(400, "删除失败");
        }
    }
    //审核通过
    @Override
    public Result<String> updateInventoryAdjustmentAgree(String document_ID) {
        int falseNum = 0;
            //判断对应ID的订单状态是否为1与2，如果是,则返回当前订单状态为1——审核通过，2——审核拒绝，如果不是则将订单状态改为1
            System.out.println( document_ID);
            int i = iiad.updateInventoryAdjustmentAgree(document_ID);
            if (i > 0) {
                return Result.success(document_ID + "审核通过");
            } else {
                return Result.failure(400, "审核状态为" + 1 + "，请勿重复审核");
            }
    }
    //审核不通过
    @Override
    public Result<String> updateInventoryAdjustmentRefuse(String document_ID) {
        int falseNum = 0;
            //判断对应ID的订单状态是否为1与2，如果是,则返回当前订单状态为1——审核通过，2——审核拒绝，如果不是则将订单状态改为1
            int i = iiad.updateInventoryAdjustmentRefuse(document_ID);
            if (i > 0) {
                return Result.success(document_ID + "审核拒绝");
            } else {
                return Result.failure(400, "审核状态为" + 2 + "，请勿重复审核");
            }
    }
}
